package cn.duli.xianer.service.impl;

import cn.duli.xianer.dao.UsersMapper;
import cn.duli.xianer.pojo.MyResult;
import cn.duli.xianer.pojo.Users;
import cn.duli.xianer.service.UsersService;
import cn.duli.xianer.utils.StrUtil;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UsersServiceImpl implements UsersService {

    @Resource
    private UsersMapper usersMapper;

    @Override
    public int save(Users user) {
        user.setuRole("user");
        user.setUsername(StrUtil.getStr());
        user.setuAvatar("http://imgs.duli1126.cn/Fi-WU4zsZ-1OTVfPg5OXyIao13SP");
        user.setuBio("这家伙很懒，什么都没留下。");
        user.setuName("小贰");
        usersMapper.save(user);
        return user.getuId();
    }

    @Override
    public void updateLastLoginTime(Users user) {
        usersMapper.updateLastLoginTime(user);
    }

    @Override
    public Users findById(Integer uId) {
        return usersMapper.findById(uId);
    }

    @Override
    public Users findByUsername(String username) {
        return usersMapper.findByUsername(username);
    }

    @Override
    public void update(Users user) {
        usersMapper.update(user);
    }

    @Override
    public void updateAvatar(Users user) {
        usersMapper.updateAvatar(user);
    }

    @Override
    public void deleteById(Integer uId) {
        usersMapper.deleteById(uId);
    }

    @Override
    public Page<Users> findAll() {
        return usersMapper.findAll();
    }

    @Override
    public void updateRole(Users user) {
        usersMapper.updateRole(user);
    }

    @Override
    public int findUsersCount() {
        return usersMapper.findUsersCount();
    }

    @Override
    public int findBusinessCount() {
        return usersMapper.findBusinessCount();
    }

}
